home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '90 / Source Code ƒ / MPW C ƒ / Prec ƒ / PREC Folder / makePREC.c next >
Encoding:
C/C++ Source or Header  |  1989-11-18  |  1.9 KB  |  98 lines  |  [TEXT/MPS ]

  1. /*    PREC Maker - by John Jeppson
  2.  
  3.     This is an MPW C tool which calls PrStlDialog and
  4.     PrJobDialog and then makes a PREC resource from the
  5.     resulting print record.
  6.  
  7.     Execute the following MPW command line:
  8.         makePREC id title destFile
  9.     
  10.             example:  makePREC  1001  "my prec"  prec.rsrc
  11.             
  12.     Creates <destFile> if it does not already exist.
  13.     Removes/replaces any pre-existing PREC resources
  14.       with the same ID number in <destFile>.
  15. */
  16.  
  17.  
  18. #include <Printing.h>
  19. #include <Files.h>
  20. #include <Resources.h>
  21. #include <Memory.h>
  22. #include <Fonts.h>
  23.  
  24. THPrint        hPrint;
  25.  
  26. void makePrintRecord()
  27. {
  28.     Boolean        err;
  29.     
  30.     hPrint = (THPrint) NewHandle(sizeof(TPrint));
  31.     if ( hPrint == 0L )
  32.     {
  33.         printf ("Cannot allocate hPrint\n");
  34.         exit(2);
  35.     }
  36.     PrOpen();
  37.     PrintDefault (hPrint);
  38.     err = PrStlDialog (hPrint);
  39.     err = PrJobDialog (hPrint);
  40.     PrClose();
  41. }
  42.  
  43. void openDestFile(Str255 rsrcfile)
  44. {
  45.     CreateResFile (rsrcfile);
  46.     (void) OpenRFPerm (rsrcfile, 0, fsWrPerm);
  47.     if (ResError()) {
  48.         printf ("Cannot open dest file, error# %d", ResError());
  49.         exit(2);
  50.         }
  51. }
  52.  
  53.  
  54. void checkPreexisting(ResType theType, short theID)
  55. {    
  56.     SetResLoad (false);
  57.     if (Get1Resource (theType, theID))
  58.             do 
  59.                 RmveResource (Get1Resource (theType, theID));
  60.             while
  61.                 (ResError() == noErr);        
  62.     SetResLoad (true);
  63. }
  64.  
  65.  
  66. int main (int argc,            /* number of arguments */
  67.             char *argv[],        /* pointer to array of argument strings */
  68.             char *envp[])        /* pointer to array of variable definitions */
  69. {
  70.     #pragma unused (envp)
  71.  
  72.     short    theID;
  73.     ResType    theType;
  74.     
  75.     InitGraf((Ptr) &qd.thePort);
  76.     SetFScaleDisable(true);
  77.  
  78.     if ( argc != 4 )
  79.     {
  80.         printf ("### Wrong Number of Parameters ###\n");
  81.         return 2;
  82.     }
  83.  
  84.     theType = 'PREC';
  85.     theID   = (short) atol(argv[1]);
  86.     (void) c2pstr(argv[2]);
  87.     (void) c2pstr(argv[3]);
  88.     
  89.     InitCursor();
  90.     makePrintRecord();
  91.     openDestFile(argv[3]);
  92.     checkPreexisting(theType, theID);
  93.     AddResource ((Handle) hPrint, theType, theID, argv[2]);
  94.  
  95.     return 0;
  96. }
  97.  
  98.